﻿//-----------------------------------------------------------------------
// <copyright file="Products.cs" company="Craig Longford (deltawolf7@gmail.com)">
//     Copyright (c) Craig Longford. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Delta.Mercury.Business.Commerce
{
    using System;
    using System.Collections.Generic;
    using Delta.Data.DataExpress;

    /// <summary>
    /// Collection of products
    /// </summary>
    [Serializable]
    public class Products : List<IProduct>, IComparer<IProduct>
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the Products class.
        /// </summary>
        public Products()
        {
        }
        #endregion

        #region Load Methods
        /// <summary>
        /// Load products by category
        /// </summary>
        /// <param name="category">Category indentity</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of products</returns>
        public static Products Load(ICategory category, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("CategoryGuid", category.Guid));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Products, Product>("LoadProducts", System.Data.CommandType.StoredProcedure, parameters);
        }

        /// <summary>
        /// Load products
        /// </summary>
        /// <param name="number">Number to show</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of products</returns>
        public static Products Load(int number, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("Number", number));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Products, Product>("LoadProducts", System.Data.CommandType.StoredProcedure, parameters);
        }

        /// <summary>
        /// Load products
        /// </summary>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of products</returns>
        public static Products Load(bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Products, Product>("LoadProducts", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Search Methods
        /// <summary>
        /// Search products
        /// </summary>
        /// <param name="query">Search query</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of products</returns>
        public static Products Search(string query, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("Deleted", showDeleted));
            parameters.Add(new Parameter("Query", query));
            return DataAccess.GetCollection<Products, Product>("SearchProducts", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Compare Methods
        /// <summary>
        /// Compare objects
        /// </summary>
        /// <param name="x">First object</param>
        /// <param name="y">Second object</param>
        /// <returns>Match or not</returns>
        public int Compare(IProduct x, IProduct y)
        {
            return x.SKU.CompareTo(y.SKU);
        }
        #endregion
    }
}
